import java.util.Scanner;
public class ShoppingSystem {
    public static void main(String[] args)
    {
       String name;
        Goods g1 = new Goods("xuebi","drink",3,50);
        Goods g2 = new Goods("kele","drink",3,50);
        Goods g3 = new Goods("apple","fruit",2,30);
        Goods g4 = new Goods("banana","fruit",2,20);
        Scanner s = new Scanner(System.in);
        ShoppingCart[] arr = new ShoppingCart[4];


        while(true)
        {
            System.out.println("温馨提示:如果您想退出，请输入exit");

            System.out.println("请输入您要选择的商品：");
            name = s.next();
            if(s.next().equals("exit"))
            {
                break;
            }
            if(name.equals(g1.getName()))
            {
                System.out.println("商品信息如下：");
                System.out.println("商品名称为：" + g1.getName());
                System.out.println("商品种类为：" + g1.getType());
                System.out.println("商品价格为：" + g1.getPrice());
                System.out.println("商品库存为：" + g1.getNum());
                System.out.println("请选择是否添加至购物车(如果是请输入Yes,否输入No)");
                if(s.next().equals("Yes"))
                {
                    //添加至购物车
                    System.out.println("请输入您要购买的数量：");
                    int n;
                    n = s.nextInt();
                    ShoppingCart c1 = new ShoppingCart("g1.getName()",g1.getPrice(),n);
                  arr[0] = c1;
                }
                else {}
            }
            if(name.equals(g2.getName()))
            {
                System.out.println("商品信息如下：");
                System.out.println("商品名称为：" + g2.getName());
                System.out.println("商品种类为：" + g2.getType());
                System.out.println("商品价格为：" + g2.getPrice());
                System.out.println("商品库存为：" + g2.getNum());
                System.out.println("请选择是否添加至购物车(如果是请输入Yes,否输入No)");
                if(s.next().equals("Yes"))
                {
                    //添加至购物车
                    System.out.println("请输入您要购买的数量：");
                    int n;
                    n = s.nextInt();
                    ShoppingCart c2 = new ShoppingCart("g2.getName()",g2.getPrice(),n);
                 arr[1] = c2;
                }
                else {}
            }
            if(name.equals(g3.getName()))
            {
                System.out.println("商品信息如下：");
                System.out.println("商品名称为：" + g3.getName());
                System.out.println("商品种类为：" + g3.getType());
                System.out.println("商品价格为：" + g3.getPrice());
                System.out.println("商品库存为：" + g3.getNum());
                System.out.println("请选择是否添加至购物车(如果是请输入Yes,否输入No)");
                if(s.next().equals("Yes"))
                {
                    //添加至购物车
                    System.out.println("请输入您要购买的数量：");
                    int n;
                    n = s.nextInt();
                    ShoppingCart c3 = new ShoppingCart("g3.getName()",g3.getPrice(),n);
                    arr[2] = c3;
                }
                else {}
            }

            if(name.equals(g4.getName()))
            {
                System.out.println("商品信息如下：");
                System.out.println("商品名称为：" + g4.getName());
                System.out.println("商品种类为：" + g4.getType());
                System.out.println("商品价格为：" + g4.getPrice());
                System.out.println("商品库存为：" + g4.getNum());
                System.out.println("请选择是否添加至购物车(如果是请输入Yes,否输入No)");
                if(s.next().equals("Yes"))
                {
                //添加至购物车
                    System.out.println("请输入您要购买的数量：");
                    int n;
                    n = s.nextInt();
                    ShoppingCart c4 = new ShoppingCart("g4.getName()",g4.getPrice(),n);
                    arr[3] = c4;
                }
                else {}


            }
        }


        System.out.println("购物车现有商品如下：");
        ShoppingCar(arr);

    }
   // 用户自我选择商品，然后陈列出该类商品下的各个商品信息
    // 添加至购物车，可选择添加数量
    // 查看购物车现有商品
    //删除某商品。
    // 结算
  public static void ShoppingCar(ShoppingCart[] arr)
  {
    System.out.println("\t商品名称\t单价\t数量");
    int i;
    for(i=0;i<4;i++)
    {
        System.out.println("\t" +arr[i].getName()+ "\t" +arr[i].getPrice()+
                "\t" +arr[i].getGainnum());
    }
  }
}
